package pixivhelper.bravedefault.com;

import okhttp3.Dns;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

public class PixivDns implements Dns {
    @Override
    public List<InetAddress> lookup(String hostname) throws UnknownHostException {
        Hostname[] pixivHostnames = Hostname.all();
        for (int i =0;i<pixivHostnames.length;i++) {
            Hostname pixivHostname = pixivHostnames[i];
            if (pixivHostname.getRawValue().equals(hostname)) {
                String address = pixivHostname.address();
                List<InetAddress> inetAddresses = Arrays.asList(InetAddress.getAllByName(address));
                return inetAddresses;
            }
        }
        return Dns.SYSTEM.lookup(hostname);
    }
}
